require 'rubygems'
require 'pinyin'

class InitAreasKeyWords < ActiveRecord::Migration
  def self.up
    add_column :areas,:key_words, :string
    Area.all.each_with_index do |area,index|
      py = Pinyin.new
      puts "#{index}. #{area.short_name}"
      area.update_attribute :key_words, "#{area.short_name} #{py.to_pinyin(area.short_name,'',false).upcase} #{py.to_pinyin_abbr(area.short_name).upcase}"
    end if not Rails.env.test?
  end

  def self.down
    remove_column :areas, :key_words
  end
end
